package DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class InterfaceBanco {

	static String server = "localhost", user = "sa", passwd = "123456";
	static String connectionString = "";

	public static Statement conecta() throws SQLException {

		Connection con;
		Statement statementRetorno;

		try {
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

		} catch (java.lang.ClassNotFoundException e) {
			System.err.print("ClassNotFoundException: ");
			System.err.println(e.getMessage());
			return null;
		}

		con = DriverManager.getConnection(server, user, passwd);
		statementRetorno = con.createStatement();

		return statementRetorno;

	}

	public static ResultSet Busca(String query) throws SQLException {
		ResultSet resultado;
		Statement stmt = conecta();

		resultado = stmt.executeQuery(query);

		stmt.close();

		return resultado;
	}

	public static int Atualiza(String query) throws SQLException {
		int resultado;
		Statement stmt = conecta();

		resultado = stmt.executeUpdate(query);

		stmt.close();

		return resultado;
	}
}
